package com.abc.robot01.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.DpSize
import com.abc.robot01.R
import com.abc.robot01.vivemodel.WaitingViewModel

/**
 * 渲染
 */
class WaitingActivity : BaseVoiceActivity() {

    private val viewModel: WaitingViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val  time  = viewModel.time.observeAsState()
            val scrollState = rememberScrollState()
            MaterialTheme {
                Box {
                    Image(painter = painterResource(id = R.drawable.z1), contentDescription = "")
                    Row(modifier = Modifier.padding(30.px)) {
                        BackButton{
                            this@WaitingActivity.finish()
                        }
                        Spacer(modifier = Modifier.width(82.px))
                        Column(modifier = Modifier
                            .fillMaxHeight()
                            .width(1400.px)) {
                            Title() {
                                IndeterminateCircularIndicator()
                                Spacer(modifier = Modifier.height(30.px))
                                BasicText(
                                    text = "渲染设计已提交，请耐心等待...",
                                    style = TextStyle(
                                        fontSize = 30.mysp,
                                        color = MYBLACK,
                                        fontWeight = FontWeight.Bold
                                    ),
                                )
                                Spacer(modifier = Modifier.height(20.px))
                                BasicText(
                                    text = "预计在${time.value} 分前完成渲染",
                                    style = TextStyle(
                                        fontSize = 24.mysp,
                                        color = MYBLACK,
                                    ),
                                )

                                Spacer(modifier = Modifier.height(40.px))
                                BasicText(
                                    text = "您可以先返回首页查看其它方案",
                                    style = TextStyle(
                                        fontSize = 20.mysp,
                                        color = MYBLACK_Percent60,
                                    ),
                                )

                                Spacer(modifier = Modifier.height(20.px))
                                BasicText(
                                    text = "设计结果可在我的渲染记录中查看",
                                    style = TextStyle(
                                        fontSize = 20.mysp,
                                        color = MYBLACK_Percent60,
                                    ),
                                )
                                Spacer(modifier = Modifier.height(60.px))

Row {
    MyButton01(
        shape = RoundedCornerShape(10.px),
        containerColor = MYBLACK_Percent10, textColor = MYBLACK, fontSize = 30.mysp,
    text = "回到首页",
        size = DpSize(320.px,70.px)){
        startActivity<BaseActivity>(){
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        }
        finish()
    }
    Spacer(modifier = Modifier.width(30.px))
    MyButton01(
        shape = RoundedCornerShape(10.px),
        containerColor = MYBLUE, textColor = Color.White, fontSize = 30.mysp,
        text = "渲染记录",
        size = DpSize(320.px,70.px)){
 startActivity<SysMessageActivity>(){
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
 }
        finish()
    }
}

                            }


                        }
                    }
                }
            }
        }
        Log.e(TAG, "onCreate");
    }

    /**
     *   定义一个title ,下面是内容 ,
     *   例子可以查看: https://www.figma.com/design/7YtLSgj000mxvLmuyPJynl/%E4%B8%80%E6%9D%9F%E5%85%89%E7%A7%91%E6%8A%80--%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%AB%AF?node-id=385-11603&node-type=CANVAS&t=K4gI0sJdooGo8tU4-0
     */
    @Composable
    fun Title(content: @Composable ColumnScope.() -> Unit) {
            Card(
                colors = androidx.compose.material3.CardDefaults.cardColors(
                    containerColor = Color.White // 设置背景色为白色
                ),
                modifier = Modifier
                    .width(1400.px)
//                    .heightIn(min = 90.px)
                    .background(Color.Transparent),
                shape = RoundedCornerShape(20.px
                )
            ) {
                Column(modifier = Modifier
                    .fillMaxSize()
                    .padding(start = 30.px, top = 30.px, bottom = 30.px)
                , horizontalAlignment = Alignment.CenterHorizontally
                ) {
//                    Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier
//                        .background(Color.Transparent)
//                        .clickable {
//                        }) {
////                        BasicText(
////                            text = title,
////                            style = TextStyle(
////                                fontSize = MyFont_Size,
////                                color = Color.Black,
////                                fontWeight = FontWeight.Bold
////                            ),
////                        )
//                    }
//                        Spacer(modifier = Modifier.height(30.px))
                    content()
                }
            }
        }

    companion object {
        val TAG = "WaitingActivity"
    }

}

@Composable
fun IndeterminateCircularIndicator() {
    CircularProgressIndicator(
        modifier = Modifier.size(140.px),
//        color = Color.Red,
        trackColor = MYBLUE,
    )
}
